﻿/**
 * Author: Junaid P V
 * License: New BSD License
 **/
using System;
using System.Collections.Generic;

namespace Org.AI.Neural
{
    /// <summary>
    /// Class that host some prediates that helps to find neuron(s) on network
    /// for a particular criteria.
    /// </summary>
    class NeuralNetworkPredicates
    {
        /// <summary>
        /// Represetns layer number.
        /// This value should be set before calling predicates depending it.
        /// </summary>
        public int layer;

        /// <summary>
        /// Represents id of a neuron on network.
        /// This value should be set before calling predicates depending it.
        /// </summary>
        public int id;

        /// <summary>
        /// Constructor that initialize object to defaut state.
        /// </summary>
        public NeuralNetworkPredicates()
        {
            this.layer = 0;
            this.id = 0;
        }
        
        /// <summary>
        /// It is a predicate helps to find a neuron with particular id.
        /// The id value should be set to this calss instance prior to calling
        /// this predicate.
        /// </summary>
        /// <param name="neuron">Neuron that is matched by this predicate.</param>
        /// <returns></returns>
        public bool NeuronWithId(Neuron neuron)
        {
            if (neuron.Id == this.id) return true;
            else return false;
        }

        /// <summary>
        /// Predicate that helps to find all neuron on a particular layer.
        /// Input layer number is 0 and output layer is -1. Hidden layers are
        /// numbered 1,2,3,..etc from input layer to output layer. i.e, layer next to
        /// input layer is 1 then 2 and so on.
        /// </summary>
        /// <param name="neuron">Neuron that is matched by this predicate.</param>
        /// <returns></returns>
        public bool NeuronOnLayer(Neuron neuron)
        {
            if (neuron.Layer == this.layer) return true;
            else return false;
        }

        /// <summary>
        /// Helps to find connection in the list having neuron with given id.
        /// </summary>
        /// <param name="connection">InputConnection that is matched for having neuron with specified id</param>
        /// <returns></returns>
        public bool InputConnectionWithNeuron(NeuronConnection connection)
        {
            if (connection.Neuron.Id == this.id) return true;
            else return false;
        }

        /// <summary>
        /// Set id number for the predicate(s)
        /// </summary>
        /// <param name="id">id number</param>
        /// <returns>self reference</returns>
        public NeuralNetworkPredicates SetId(int id)
        {
            this.id = id;
            return this;
        }

        /// <summary>
        /// Set layer number for the predicate(s)
        /// </summary>
        /// <param name="layer">layer number</param>
        /// <returns>self reference</returns>
        public NeuralNetworkPredicates SetLayer(int layer)
        {
            this.layer = layer;
            return this;
        }
    }
}
